package twice.class01;

/**
 * @author ywb
 * @Description:
 * @date 2023/6/15 16:31
 */
public class Class03_Insert {
    public static void bubbleSort(int[] arr) {
        for(int i = 1;i < arr.length;i++){
            for (int j = i - 1; j >= 0 && arr[j] > arr[j + 1]; j--) {
                swap(arr, j, j + 1);
            }
        }
    }

    public static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{8,7,5,2,6,4,3,1,9};
        bubbleSort(arr);
        for (int i : arr) {
            System.out.print(i);
        }
    }
}
